package com.medic.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.medic.entity.Assitant;
import com.medic.entity.Weichat;
import com.medic.mapper.interf.AssitantMapper;
import com.medic.service.interf.AssitantServiceInterface;
import com.medic.util.CacheUtil;
 


@Service("assitantService")
@Transactional(readOnly = false,propagation = Propagation.REQUIRED, rollbackFor = Exception.class)// 注明需要回滚
public class AssitantServiceImpl implements AssitantServiceInterface {





	@Resource
	private AssitantMapper assitantMapper;
	
	@Resource
	private WeichatServiceImpl weichatService;
	
	
	@Override
	public boolean delete(Assitant object) throws Exception {
		assitantMapper.delete(object);
		return true;
	}

	@Override
	public boolean save(Assitant ast) throws Exception {
				
		assitantMapper.save(ast);
		
		
		Weichat wechat = new Weichat();
		wechat.setOpenid(ast.getOpenid());
		wechat.setRole("assitant");
		wechat.setRolename(ast.getName());
		wechat.setRoleid(ast.getId()); 
		
		
		weichatService.save(wechat);
		
		return true;
	}

	@Override
	public boolean update(Assitant object) throws Exception {
		assitantMapper.update(object);
		return true;
	}
	
	

	
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	@Override
	public Assitant getAssitant(int assitantid) throws Exception {
		
		return assitantMapper.selectAssitantByID(assitantid);
	}

	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public Page<Assitant> getAssitant(int pageno, String where)
			throws Exception {
		PageHelper.startPage(pageno,  CacheUtil.getRole_pagesize());
		
		Page<Assitant> page = (Page<Assitant>)assitantMapper.selectAssitant(where); 
		
		return page;

	}
	
	
}
